package com.example.its2020008;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import androidx.appcompat.widget.Toolbar;


import com.example.its2020008.fragment.EnviFragment;
import com.example.its2020008.fragment.Topic2Fragment;
import com.example.its2020008.fragment.Topic3Fragment;
import com.example.its2020008.fragment.Topic4Fragment;
import com.example.its2020008.fragment.Topic5Fragment;
import com.google.android.material.navigation.NavigationView;

public class mLogin extends AppCompatActivity {


    private Toolbar toolbar;
    private DrawerLayout drawerLayout;
    private FrameLayout frameLayout;
    private NavigationView navigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mlogin);
        initView();
        Intent intent=getIntent();
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        ActionBarDrawerToggle toggle=new ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.app_name,R.string.app_name){
            @Override
            public  void  onDrawerOpened(View drawerView){
                super.onDrawerOpened(drawerView);
            }
            @Override
            public  void  onDrawerClosed(View drawerView){
                super.onDrawerClosed(drawerView);
            }
        };
        toggle.syncState();
        drawerLayout.addDrawerListener(toggle);

        getSupportFragmentManager().beginTransaction()
                .add(R.id.framelayout, EnviFragment.newInstance("",""),"")
                .commit();
        toolbar.setTitle("智能交通系统");
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                item.setCheckable(true);
                switch (item.getItemId()){
                    case  R.id.topic_1:
                        getSupportFragmentManager().beginTransaction()
                                .replace(R.id.framelayout,EnviFragment.newInstance("",""),"")
                                .commit();
                        toolbar.setTitle("首页");
                        break;
                    case  R.id.topic_2:
                        getSupportFragmentManager().beginTransaction()
                                .replace(R.id.framelayout, Topic2Fragment.newInstance("",""),"")
                                .commit();
                        toolbar.setTitle("环境指标");
                        break;
                    case  R.id. topic_3:
                        getSupportFragmentManager().beginTransaction()
                                .replace(R.id.framelayout, Topic3Fragment.newInstance("",""),"")
                                .commit();
                        toolbar.setTitle("阈值设置");
                        break;
                    case R.id.topic_4:
                        getSupportFragmentManager().beginTransaction()
                                .replace(R.id.framelayout, Topic4Fragment.newInstance("",""),"")
                                .commit();
                        toolbar.setTitle("ETC账户");
                        break;
                    case  R.id.topic_5:
                        getSupportFragmentManager().beginTransaction()
                                .replace(R.id.framelayout, Topic5Fragment.newInstance("",""),"")
                                .commit();
                        toolbar.setTitle("交通灯");
                        break;
                    case  R.id.topic_6:
                        mLogin.this.finish();
                        break;

                }
                drawerLayout.closeDrawers();
                return  true;
            }
        });

        }

    private void initView() {
        toolbar = (Toolbar)findViewById(R.id.toolbar);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        frameLayout = (FrameLayout) findViewById(R.id.framelayout);
        navigationView = (NavigationView) findViewById(R.id.navigation);
       
    }
}